package com.alks.entity.data.enums.factoryquery;
import lombok.Getter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

    @Getter
    public enum PcCuttingProcecssEnum {
        PROCESS_CUT("冲裁","01"),
        PROCESS_HF("工艺","02"),
        PROCESS_SP("配套","03");

        private String processName;
        private String processCode;

        PcCuttingProcecssEnum(String processName, String processCode) {
            this.processName=processName;
            this.processCode=processCode;
        }

        public static Map<String, String> toMap() {
            Map<String, String> map = new HashMap<>();
            for (PcCuttingProcecssEnum process : PcCuttingProcecssEnum.values()) {
                map.put(process.getProcessName(), process.getProcessCode());
            }
            return map;
        }

        public static Map<String, String>[] toMapArray() {
            int i=0;
            Map<String, String> map[] = new HashMap[PcCuttingProcecssEnum.values().length];
            for (int j = 0; j < map.length; j++) {
                map[j] = new HashMap<>();
            }
            for (PcCuttingProcecssEnum process : PcCuttingProcecssEnum.values()) {
                map[i].put("name", process.getProcessName());
                map[i].put("code", process.getProcessCode());
                i++;
            }
            return map;
        }

        public static List<String> getNameList(){
            return Arrays.stream(PcCuttingProcecssEnum.values()).map(PcCuttingProcecssEnum::getProcessName).collect(Collectors.toList());
        }

        /**
         * 根据工艺名找工艺ID
         * @param processName
         * @return
         */
        public static String getCodeByName(String processName){
            return toMap().get(processName);
        }

        /**
         * 判断给定的processCode是否存在于枚举中
         * @param processCode 要检查的processCode
         * @return 如果processCode存在则返回true，否则返回false
         */
        public static boolean isProcessCodeExist(String processCode) {
            for (PcCuttingProcecssEnum lsTypeEnum : values()) {
                if (lsTypeEnum.getProcessCode().equals(processCode)) {
                    return true;
                }
            }
            return false;
        }
    }
